package de.dhbw.karlsruhe.picsim.util.impl;

import de.dhbw.karlsruhe.picsim.util.Bits;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 15, 2010
 * Time: 9:26:38 AM
 */
public abstract class BitSetSupport implements Bits {


    @SuppressWarnings({"InstanceofInterfaces"})
    @Override
    public final boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof BitSetSupport)) {
            return false;
        }
        final Bits that = (Bits) obj;
        if (that.getLength() != getLength()) {
            return false;
        }
        for (int i = 0; i < getLength(); i++) {
            if (that.isSet(i) != isSet(i)) {
                return false;
            }
        }
        return true;
    }

    @Override
    public final int hashCode() {
        return BitUtilities.fromMostSignificantBitFirst(this);
    }
}
